/**Created by the LayaAirIDE*/
package view
{
	import ui.GameStartUI
	import laya.events.Event
	import laya.net.Loader
	import laya.utils.Handler
	import laya.utils.Tween
	import laya.utils.Ease

	public class GameStart extends GameStartUI
	{
		private var assetArr:Array = [
			{url:"res/atlas/gameRole.atlas"},
			{url:"sound/achievement.mp3", type:Loader.SOUND},
			{url:"sound/bullet.mp3", type:Loader.SOUND},
			{url:"sound/game_over.mp3", type:Loader.SOUND},
			{url:"sound/enemy1_die.mp3", type:Loader.SOUND},
			{url:"sound/enemy3_out.mp3", type:Loader.SOUND},
		];

		public function GameStart() 
		{
			this.btn_start.visible = false;

			this.once(Event.CLOSE, this, onClose);

			Laya.loader.load(assetArr, Handler.create(this, onComplete), Handler.create(this, onProgress));
		}

		private function onClose():void {
			this.removeSelf();

			this.destroy();
		}

		private function onComplete(): void {
			this.txt_load.text = "资源加载完成";

			this.btn_start.visible = true;

			Tween.from(this.btn_start, {y:this.btn_start.y + 20}, 1000, Ease.elasticOut);
		}

		private function onProgress(loadNum:Number):void {
			this.txt_load.text = "资源加载中，进度：" + (loadNum * 100).toString() + "%";
		}
		
	}

}